/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#include "Game/Game/Player.h"
#include "Shared/Log/Log.h"
#include "Game/Game/DBCStores.h"
#include "Game/Game/ObjectManager.h"


bool Player::isActionButtonDataValid(std::uint8_t button, std::uint32_t action, std::uint8_t type, Player* player)
{
    // TODO

    if (button >= MAX_ACTION_BUTTONS)
    {
        if (player)
        { /*sharedLog.outError("Action %u not added into button %u for player %s: button must be < %u", action, button, player->GetName(), MAX_ACTION_BUTTONS);*/ }
        else
        { sharedLog.outError("Table `playercreateinfo_action` have action %u into button %u : button must be < %u", action, button, MAX_ACTION_BUTTONS); }
        return false;
    }

    if (action >= MAX_ACTION_BUTTON_ACTION_VALUE)
    {
        if (player)
        { /*sharedLog.outError("Action %u not added into button %u for player %s: action must be < %u", action, button, player->GetName(), MAX_ACTION_BUTTON_ACTION_VALUE);*/ }
        else
        { sharedLog.outError("Table `playercreateinfo_action` have action %u into button %u : action must be < %u", action, button, MAX_ACTION_BUTTON_ACTION_VALUE); }
        return false;
    }

    switch (type)
    {
    case ACTION_BUTTON_SPELL:
        {
            SpellEntry const* spellProto = dbcStores.spellStore().lookupEntry(action);
            if (!spellProto)
            {
                if (player)
                { /*sharedLog.outError("Spell action %u not added into button %u for player %s: spell not exist", action, button, player->GetName());*/ }
                else
                { sharedLog.outError("Table `playercreateinfo_action` have spell action %u into button %u: spell not exist", action, button); }
                return false;
            }

            //if (player)
            //{
            //    if (!player->HasSpell(spellProto->Id))
            //    {
            //        sLog.outError("Spell action %u not added into button %u for player %s: player don't known this spell", action, button, player->GetName());
            //        return false;
            //    }
            //    else if (IsPassiveSpell(spellProto))
            //    {
            //        sLog.outError("Spell action %u not added into button %u for player %s: spell is passive", action, button, player->GetName());
            //        return false;
            //    }
            //}
            break;
        }
    case ACTION_BUTTON_ITEM:
        {
            if (!gameObjectMgr.getItemPrototype(action))
            {
                if (player)
                { /*sharedLog.outError("Item action %u not added into button %u for player %s: item not exist", action, button, player->GetName());*/ }
                else
                { sharedLog.outError("Table `playercreateinfo_action` have item action %u into button %u: item not exist", action, button); }
                return false;
            }
            break;
        }
    default:
        break;                                          // other cases not checked at this moment
    }

    return true;
}